﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPages/Core.Master"
    CodeBehind="BoardMom.aspx.cs" Inherits="Pap.Web.Modules.Loan.Views.BoardMom"
    meta:resourcekey="PageResource1" %>

<%@ Register Src="../../Shared/Views/InsertAttchments.ascx" TagName="InsertAttchments"
    TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script type="text/javascript">
        var BoardpaymentRenderer = function(value) {
            var r = storeBoardPaymentMethods.getById(value);

            if (Ext.isEmpty(r)) {
                return "";
            }

            return r.data.LoanPaymentMethodName;
        }

        var BoardDecisionRenderer = function(value, metaData, record, rowIndex, colIndex, store) {
            //            debugger;
            //            var disable = record.data.Disabled;
            //            if (disable) {
            //                Ext.getCmp('grvBoardLoan').getColumnModel().getCellEditor(colIndex, rowIndex).disable();
            //            }
            //            else {
            //                Ext.getCmp('grvBoardLoan').getColumnModel().getCellEditor(colIndex, rowIndex).enable();
            //            }

            var r = storeDecisions.getById(value);
            if (Ext.isEmpty(r)) {
                return "";
            }

            return r.data.DecisionName;
        }

        var BeforeEditLoan = function(e) {
            switch (e.field) {
                case "DecisionID":
                    {
                        if (e.grid.getRowsValues(false)[e.row].Disabled)
                            this.getColumnModel().getCellEditor(e.column, e.row).field.setDisabled(true);
                        else this.getColumnModel().getCellEditor(e.column, e.row).field.setDisabled(false);
                    }
                    break;
            }
        }


        var RenderBoardStatus = function(value) {
            if (value == false)
                return '<asp:Literal runat="server" Text="<%$ Resources:BoardOpen %>" />';
            return '<asp:Literal runat="server" Text="<%$ Resources:BoardClosed %>" />';
        }


        function prepare(grid, toolbar, rowIndex, record) {
            var editable = record.data.Editable;

            var EditColumn = toolbar.items.get(0);

            if (!editable) {
                EditColumn.setDisabled(true);
            }
        }


        function prepareLoan(grid, toolbar, rowIndex, record) {
            debugger;
            var disable = record.data.Disabled;

            var EditColumn = col;

            if (disable) {
                EditColumn.setDisabled(true);
            }
        }


        var AllowEdit = function(value) {
            switch (value) {
                case "Edit":
                    {

                        if (value.grid.getRowsValues(false)[value.row].Editable) {
                            this.getColumnModel().getCellEditor(e.column, e.row).field.setDisabled(true);
                        }
                    }
                    break;
            }
        }


    
        
    </script>

    <ext:Store runat="server" IDMode="Static" ID="storeBoards" AutoLoad="true">
        <Reader>
            <ext:JsonReader ReaderID="BoardID">
                <Fields>
                    <ext:RecordField Name="BoardID" />
                    <ext:RecordField Name="BoardNumber" />
                    <ext:RecordField Name="BoardDate" Type="Date" />
                    <ext:RecordField Name="BoardStatus" />
                    <ext:RecordField Name="DecisionID" />
                    <ext:RecordField Name="StatusNotes" />
                    <ext:RecordField Name="Editable" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" IDMode="Static" ID="storeDecisions">
        <Reader>
            <ext:JsonReader ReaderID="DecisionID">
                <Fields>
                    <ext:RecordField Name="DecisionID" />
                    <ext:RecordField Name="DecisionName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" IDMode="Static" ID="storeBoardPaymentMethods">
        <Reader>
            <ext:JsonReader ReaderID="ID">
                <Fields>
                    <ext:RecordField Name="LoanPaymentMethodID" />
                    <ext:RecordField Name="LoanPaymentMethodName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store runat="server" ID="storeBoardLoans" IDMode="Static">
        <Reader>
            <ext:JsonReader ReaderID="LoanID">
                <Fields>
                    <ext:RecordField Name="LoanID" />
                    <ext:RecordField Name="LoanNumber" />
                    <ext:RecordField Name="LoanCreatedDate" Type="Date" />
                    <ext:RecordField Name="CustomerName" />
                    <ext:RecordField Name="LoanType" />
                    <ext:RecordField Name="LoanAmount" />
                    <ext:RecordField Name="FeasibleLoanAmount" />
                    <ext:RecordField Name="FeasibleLoanPaymentPeriod" />
                    <ext:RecordField Name="BoardLoanAmount" />
                    <ext:RecordField Name="BoardPaymentPeriod" />
                    <ext:RecordField Name="BoardpaymentMethodID" />
                    <ext:RecordField Name="StatusNotes" />
                    <ext:RecordField Name="PreviousNotes" />
                    <ext:RecordField Name="DecisionID" />
                    <ext:RecordField Name="Disabled" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:FitLayout runat="server">
        <ext:FormPanel runat="server" ID="fpanlBoardMom" AutoScroll="true">
            <Body>
                <ext:FormLayout runat="server">
                    <ext:Anchor>
                        <ext:GridPanel runat="server" ID="grvBoards" IDMode="Static" StoreID="storeBoards"
                            Title="<%$Resources:grvBoardsTitle %>" TrackMouseOver="true" meta:resourcekey="grvBoardsResource1"
                            AutoHeight="true" AutoScroll="true" AutoWidth="true">
                            <ColumnModel>
                                <Columns>
                                    <ext:Column DataIndex="BoardNumber" Header="<%$Resources:grvHeaderBoardNumber %>" />
                                    <ext:Column DataIndex="BoardDate" Header="<%$Resources:grvHeaderBoardDate%>">
                                        <Renderer Fn="Ext.util.Format.dateRenderer('d/m/Y')" />
                                    </ext:Column>
                                    <ext:Column DataIndex="BoardStatus" Header="<%$Resources:grvHeaderBoardStatus%>" />
                                    <ext:Column DataIndex="StatusNotes" Header="<%$Resources:grvHeaderStatusNotes %>">
                                        <Editor>
                                            <ext:TextField runat="server" />
                                        </Editor>
                                    </ext:Column>
                                    <ext:CommandColumn>
                                        <Commands>
                                            <ext:GridCommand Icon="NoteEdit" CommandName="EditColumn" />
                                        </Commands>
                                        <PrepareToolbar Fn="prepare" />
                                    </ext:CommandColumn>
                                </Columns>
                            </ColumnModel>
                            <AjaxEvents>
                                <Command OnEvent="GrvBoards_Command">
                                    <ExtraParams>
                                        <ext:Parameter Name="GridCommand" Value="command" Mode="Raw" Encode="false" />
                                    </ExtraParams>
                                </Command>
                            </AjaxEvents>
                            <SelectionModel>
                                <ext:RowSelectionModel>
                                    <AjaxEvents>
                                        <RowSelect OnEvent="Board_Selected" Before="#{grvBoardLoan}.body.mask('...', 'x-mask-loading');"
                                            Success="#{grvBoardLoan}.body.unmask();">
                                            <ExtraParams>
                                                <ext:Parameter Name="Editable" Value="record.data.Editable" Mode="Raw" Encode="false" />
                                            </ExtraParams>
                                        </RowSelect>
                                    </AjaxEvents>
                                </ext:RowSelectionModel>
                            </SelectionModel>
                        </ext:GridPanel>
                    </ext:Anchor>
                    <ext:Anchor>
                        <ext:GridPanel runat="server" ID="grvBoardLoan" IDMode="Static" StoreID="storeBoardLoans"
                            Title="<%$Resources:grvBoardLoansTitle %>" TrackMouseOver="true" AutoHeight="true"
                            Footer="True" AutoScroll="true" AutoWidth="true">
                            <ColumnModel>
                                <Columns>
                                    <ext:Column DataIndex="LoanNumber" Header="<%$Resources:grvHeaderLoanNumber %>" />
                                    <ext:Column DataIndex="CustomerName" Header="<%$Resources:grvHeaderCustomerName %>" />
                                    <ext:Column DataIndex="LoanCreatedDate" Header="<%$Resources:grvHeaderLoanCreatedDate %>">
                                        <Renderer Fn="Ext.util.Format.dateRenderer('d/m/Y')" />
                                    </ext:Column>
                                    <ext:Column DataIndex="LoanType" Header="<%$Resources:grvHeaderLoanType %>" />
                                    <ext:Column DataIndex="LoanAmount" Header="<%$Resources:grvHeaderLoanAmount %>" />
                                    <ext:Column DataIndex="FeasibleLoanAmount" Header="<%$Resources:grvHeaderFeasibleLoanAmount %>" />
                                    <ext:Column DataIndex="FeasibleLoanPaymentPeriod" Header="<%$Resources:grvHeaderFeasibleLoanPaymentPeriod %>" />
                                    <ext:Column DataIndex="PreviousNotes" Header="<%$Resources:PreviousNotes %>" />
                                    <ext:CommandColumn Header="<%$Resources:grvHeaderBoardDecision %>" DataIndex="DecisionID">
                                        <Renderer Fn="BoardDecisionRenderer" />
                                        <Editor>
                                            <ext:ComboBox runat="server" ID="cmbBoardDecision" StoreID="storeDecisions" DisplayField="DecisionName"
                                                ValueField="DecisionID" AllowBlank="false" TypeAhead="true">
                                            </ext:ComboBox>
                                        </Editor>
                                    </ext:CommandColumn>
                                    <ext:Column DataIndex="BoardLoanAmount" Header="<%$Resources:grvHeaderBoardLoanAmount %>">
                                        <Editor>
                                            <ext:NumberField runat="server" ID="txtBoardLoanAmount" AllowBlank="false" MinValue="1"
                                                MaxValue='<%#GetMax()%>' />
                                        </Editor>
                                    </ext:Column>
                                    <ext:Column DataIndex="BoardPaymentPeriod" Header="<%$Resources:grvHeaderBoardPaymentPeriod %>">
                                        <Editor>
                                            <ext:NumberField ID="txtBoardPaymentPeriod" runat="server" AllowBlank="false" MinValue="1"
                                                MaxLength="10" MaxValue="2000" />
                                        </Editor>
                                    </ext:Column>
                                    <ext:Column DataIndex="BoardpaymentMethodID" Header="<%$Resources:grvHeaderBoardPaymentMethod %>">
                                        <Renderer Fn="BoardpaymentRenderer" />
                                        <Editor>
                                            <ext:ComboBox runat="server" ID="cmbBoardPaymentMethod" StoreID="storeBoardPaymentMethods"
                                                ValueField="LoanPaymentMethodID" DisplayField="LoanPaymentMethodName" AllowBlank="false" />
                                        </Editor>
                                    </ext:Column>
                                    <ext:Column DataIndex="StatusNotes" Header="<%$Resources:grvHeaderStatusNotes %>">
                                        <Editor>
                                            <ext:TextField ID="txtStatusNotes" runat="server" />
                                        </Editor>
                                    </ext:Column>
                                </Columns>
                            </ColumnModel>
                            <SelectionModel>
                                <ext:RowSelectionModel ID="selMoLoan" IDMode="Static" SingleSelect="true">
                                </ext:RowSelectionModel>
                            </SelectionModel>
                            <Listeners>
                                <BeforeEdit Fn="BeforeEditLoan" />
                            </Listeners>
                            <%--<AjaxEvents>
                                <BeforeEdit OnEvent="onEditLoanDes">
                                </BeforeEdit>
                            </AjaxEvents>--%>
                        </ext:GridPanel>
                    </ext:Anchor>
                    <ext:Anchor>
                        <ext:Panel runat="server">
                            <Body>
                                <uc1:InsertAttchments runat="server" ViewMode="Edit" ID="ucAttachment" />
                            </Body>
                        </ext:Panel>
                    </ext:Anchor>
                </ext:FormLayout>
            </Body>
            <BottomBar>
                <ext:StatusBar runat="server" meta:resourcekey="FormStatusBarResource1">
                    <Items>
                        <ext:Button runat="server" ID="btnPrint" Icon="Magnifier">
                            <AjaxEvents>
                                <Click OnEvent="BtnPrint_Clicked">
                                    <ExtraParams>
                                        <ext:Parameter Name="BoardMomLoansGrid" Value="Ext.encode(#{grvBoardLoan}.getRowsValues(false))"
                                            Mode="Raw" />
                                    </ExtraParams>
                                </Click>
                            </AjaxEvents>
                        </ext:Button>
                        <ext:Button runat="server" ID="btn_Cancle" Icon="ArrowUndo" meta:resourcekey="btnCancle">
                            <AjaxEvents>
                                <Click OnEvent="BtnCancle_Clicked">
                                </Click>
                            </AjaxEvents>
                        </ext:Button>
                        <ext:Button runat="server" ID="btnSave" Icon="TableSave" Text="Save" meta:resourcekey="btnSave"
                            CausesValidation="true">
                            <AjaxEvents>
                                <Click OnEvent="BtnSave_Clicked">
                                    <ExtraParams>
                                        <ext:Parameter Name="grvBoardLoanGrid" Mode="Raw" Value="Ext.encode(#{grvBoardLoan}.getRowsValues(false))" />
                                    </ExtraParams>
                                </Click>
                            </AjaxEvents>
                        </ext:Button>
                        <ext:Button runat="server" ID="btnSubmit" Text="Submit" Icon="Accept" meta:resourcekey="btnSubmit">
                            <AjaxEvents>
                                <Click OnEvent="BtnSubmit_Clicked">
                                    <ExtraParams>
                                        <ext:Parameter Name="grvBoards" Mode="Raw" Value="Ext.encode(#{grvBoards}.getRowsValues(true))" />
                                        <ext:Parameter Name="grvBoardLoanGrid" Mode="Raw" Value="Ext.encode(#{grvBoardLoan}.getRowsValues(false))" />
                                    </ExtraParams>
                                </Click>
                            </AjaxEvents>
                        </ext:Button>
                    </Items>
                    <Plugins>
                        <ext:ValidationStatus ID="wndpnlValidation" FormPanelID="fpanlBoardMom" ValidIcon="Accept"
                            ErrorIcon="Exclamation" runat="server" meta:resourcekey="wndpnlValidationResource1" />
                    </Plugins>
                </ext:StatusBar>
            </BottomBar>
        </ext:FormPanel>
    </ext:FitLayout>
    <ext:Window runat="server" ID="wndBoardMomPrint" Modal="true" ShowOnLoad="false"
        Width="550px" Height="480px">
        <AutoLoad Mode="IFrame" ShowMask="True" ManuallyTriggered="True" PassParentSize="True" />
        <%--<AjaxEvents>            
            <Close OnEvent="wndBoardMomPrint_Closed" />
        </AjaxEvents>--%>
    </ext:Window>
</asp:Content>
